package com.zlzxm.shoesmarket.view.activity;

import android.content.Context;
import android.content.Intent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.zlzxm.shoesmarket.R;
import com.zlzxm.shoesmarket.util.ZViewHelp;
import com.zlzxm.shoesmarket.view.fragment.FMCalculateOwn;
import com.zlzxm.shoesmarket.view.fragment.FMWholesaleCalculate;
import com.zlzxm.shoesmarket.view.widget.simpleead.SimpleHead;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zlz
 * on  4/24/21
 */
public class ACCalculate extends BaseActivity{


    public static void start(Context context) {
        Intent starter = new Intent(context, ACCalculate.class);
        context.startActivity(starter);
    }


    private ViewPager viewPager ;

    @Override
    protected void initView() {
        super.initView();
        setContentView(R.layout.ac_calculate);
        SimpleHead simpleHead = ZViewHelp.findById(this,R.id.head);
        simpleHead.setTitle("计算器");
        simpleHead.setOnItemclicklistener(this::finish);

        TabLayout tabLayout = ZViewHelp.findById(this,R.id.tabLayout);


        viewPager = ZViewHelp.findById(this,R.id.viewPager);

        viewPager.setAdapter(new MyPager(getSupportFragmentManager()));

        tabLayout.setupWithViewPager(viewPager);

    }




    private class MyPager extends FragmentPagerAdapter {

        List<Fragment> list = new ArrayList<>();


        public MyPager(@NonNull FragmentManager fm) {
            super(fm,FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
            list.add(new FMWholesaleCalculate());
            list.add(new FMCalculateOwn());

        }

        @NonNull
        @Override
        public Fragment getItem(int position) {
            return list.get(position);
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return position == 0 ?
                    "批发计算器":"解读计算器";
        }
    }





}
